package pers.cz.postgirl.adapter.eform;

import pers.cz.postgirl.adapter.AbstractTransformer;
import pers.cz.postgirl.config.EvenType;
import pers.cz.postgirl.core.EnhanceModel;

/**
 * @program: postgirl-client
 * @description: Boss orm框架
 * @author: Cheng Zhi
 * @create: 2023-06-09 15:58
 **/
public class EformPlugin extends AbstractTransformer {

    @Override
    public void loadEnhanceModel() {

        enhanceModel = EnhanceModel.builder()
                .classPattern("jef.database.AbstractDbClient")
                .methodPatterns(getMethodPattern())
                .build();
    }

    private EnhanceModel.MethodPattern[] getMethodPattern() {

        EnhanceModel.MethodPattern createNamedQuery = EnhanceModel.MethodPattern.builder()
                .methodName("createNamedQuery")
                .paramTypes(new String[] {"java.lang.String"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern createNativeQuery = EnhanceModel.MethodPattern.builder()
                .methodName("createNativeQuery")
                .paramTypes(new String[] {"java.lang.String"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern createNativeQuery2 = EnhanceModel.MethodPattern.builder()
                .methodName("createNativeQuery")
                .paramTypes(new String[] {"java.lang.String","java.lang.Class"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern createNativeCall = EnhanceModel.MethodPattern.builder()
                .methodName("createNativeCall")
                .paramTypes(new String[] {"java.lang.String","java.lang.reflect.Type"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern createQuery = EnhanceModel.MethodPattern.builder()
                .methodName("createQuery")
                .paramTypes(new String[] {"java.lang.String"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern createQuery2 = EnhanceModel.MethodPattern.builder()
                .methodName("createQuery")
                .paramTypes(new String[] {"java.lang.String", "java.lang.Class"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern insert = EnhanceModel.MethodPattern.builder()
                .methodName("insert")
                .paramTypes(new String[] {"jef.database.IQueryableEntity","java.lang.String", "boolean"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern delete = EnhanceModel.MethodPattern.builder()
                .methodName("delete")
                .paramTypes(new String[] {"jef.database.IQueryableEntity","java.lang.String"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern update = EnhanceModel.MethodPattern.builder()
                .methodName("update")
                .paramTypes(new String[] {"jef.database.IQueryableEntity","java.lang.String"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern pageSelect = EnhanceModel.MethodPattern.builder()
                .methodName("pageSelect")
                .paramTypes(new String[] {"java.lang.reflect.Type","int"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern innerSelect = EnhanceModel.MethodPattern.builder()
                .methodName("innerSelect")
                .paramTypes(new String[] {"java.lang.Class",
                        "jef.database.query.ConditionQuery",
                        "jef.common.wrapper.IntRange",
                        "java.util.Map",
                        "int",
                        "int",
                        "jef.common.wrapper.Holder",
                        "jef.database.QueryArg"
                })
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();
        return new EnhanceModel.MethodPattern[] {
                createNamedQuery,
                createNativeQuery,
                createNativeQuery2,
                createNativeCall,
                createQuery,
                createQuery2,
                insert,
                delete,
                update,
                innerSelect,
                pageSelect
        };
    }
}
